<?php
/**
 * 智铖样品模块模块微站定义
 *
 * @author zclc_sw
 * @url http://bbs.we7.cc/
 */
defined('IN_IA') or exit('Access Denied');
require_once 'util/Autoloader.php';
use util\DiStore;

class Zclc_sampleModuleSite extends WeModuleSite {

	public function __call($name, $arguments) {
		global $_W,$_GPC;
		$route = $this->parseWe7Callback($name);

		$diStore = DiStore::getInstance();
		$httpHandleDi = $diStore->getDi('HttpHandleDi');

		$httpHandleDi->setParameter('controller',$route['controller']);
		$httpHandleDi->setParameter('action',$route['action']);
		$httpHandleDi->setParameter('_W',$_W);
		$httpHandleDi->setParameter('_GPC',$_GPC);

		ob_start();
		$httpHandleDi['Dispatcher']->handle();
        $response = ob_get_clean();
		
		echo $response;
	}
	
	private function parseWe7Callback($name){
		global $_GPC;
		$isWeb = stripos($name, 'doWeb') === 0;
		$isMobile = stripos($name, 'doMobile') === 0;
		$dir = '';
		if($isWeb) {
			$fun = strtolower(substr($name, 5));
			$dir .= 'W_';
		}
		if($isMobile) {
			$fun = strtolower(substr($name, 8));
			$dir .= 'M_';
		}
		$callback = explode('-',$fun);
		if(empty($callback[1])){
			echo '$_GPC[\'do\']的格式请设置为 : xx-xx , 如: index-display<br>';
			echo '当$_GPC[\'do\']前值为 : '.$_GPC['do'];
			exit();
		}
		
		return ['controller'=>$dir.$callback[0],'action'=>$callback[1]];
	}
	
	
}